﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Xml.Linq;
using ClassLibrary.Entity;
using System.Collections.Generic;

public partial class MasterPage : System.Web.UI.MasterPage
{
    protected void Page_Load(object sender, EventArgs e)
    {
        btnLogout.Visible = false;
        lblAmout.Visible = false;
        lbsoluong.Visible = false;

        if (Session[Global.SESSION_LOGGED_USER] != "" &&
                   Session[Global.SESSION_LOGGED_USER] != null)
        {
            TblCustomers user = (TblCustomers)Session[Global.SESSION_LOGGED_USER];
         
                btnLogout.Visible = true;
                btnLogout.Text = "Log out";
          
                lbname.Text = ((TblCustomers)Session[Global.SESSION_LOGGED_USER]).CustomerFullname;
        }
        else
        {          
                btnLogout.Visible = false;         
        }
        LoadCSS();
        UpdateShoppingCartSession();
    }

    private void LoadCSS()
    {
        string idCSS = Global.GetPageName(Request.ServerVariables["SCRIPT_NAME"].ToString());
        if ((idCSS == "FindJob.aspx")|| (idCSS=="JobListNonWarranty.aspx")||(idCSS=="JobWarranty.aspx"))
        {
            a_JobList.Attributes.Add("class", "nav-top-item current");
        }
        if ((idCSS == "SearchCustomer.aspx")||(idCSS=="Customer.aspx"))
        {
            a_Cus.Attributes.Add("class", "nav-top-item current");
        }
        if ((idCSS == "Booking.aspx") || (idCSS == "Booking.aspx"))
        {
            a_booking.Attributes.Add("class", "nav-top-item current");
        }
        if ((idCSS == "ListProducts.aspx") || (idCSS == "PhoneBrand.aspx") || (idCSS=="ListLoanPhone.aspx"))
        {
            a_manage.Attributes.Add("class", "nav-top-item current");
        }
      
    }
   
   
    protected void btnLogout_Click1(object sender, EventArgs e)
    {
         Session.RemoveAll();
        Session.Abandon();
        Response.Redirect("~/index.html", true);
    }

    public void UpdateShoppingCartSession()
    {
        if (HttpContext.Current.Session[Global.SESSION_CART] != null)
        {
            List<TblBookingDetail> cartItems = (List<TblBookingDetail>)HttpContext.Current.Session[Global.SESSION_CART];

            int iQuantity = 0;
            decimal dAmount = 0;
            foreach (TblBookingDetail order in cartItems)
            {
                iQuantity += order.Quantity;
                //dAmount +=  order.TotalAmount;
                dAmount += order.Quantity * order.UnitPrice;
            }
            lbsoluong.Text = iQuantity.ToString();
            lblAmout.Text = dAmount.ToString("c");
        }
    }
}
